import unittest
import config.path_cfg as cfg
from parameterized import parameterized
from api.emp_api import EmpApi
from common.assert_util import AssertUtil
from common.db_util import DBUtil
from common.read_json_util import JsonUtil
from config import db_cfg


class TestLogin(unittest.TestCase):
    def setUp(self) -> None:
        # 删除"mobile": "13620920001"的数据
        dbUtil = DBUtil(host=db_cfg.host, port=db_cfg.port,
                        user=db_cfg.user, password=db_cfg.password,
                        database=db_cfg.database)
        sql = "delete from bs_user where mobile = '13620920001'"
        dbUtil.dml_sql(sql)

    def tearDown(self) -> None:
        # 删除"mobile": "13620920001"的数据
        dbUtil = DBUtil(host=db_cfg.host, port=db_cfg.port,
                        user=db_cfg.user, password=db_cfg.password,
                        database=db_cfg.database)
        sql = "delete from bs_user where mobile = '13620920001'"
        dbUtil.dml_sql(sql)

    @parameterized.expand(JsonUtil.param_data(cfg.BASE_DIR + '/data/emp_add_params.json'))
    def test_login(self, case_name, body, expect):
        print(f'用例标题：{case_name}')
        print(f'预期结果：{expect}')

        resp = EmpApi().emp_add_request(body)
        resp_data = resp.json()

        AssertUtil().assertFunc(expect, resp, resp_data)
